startSC <- function(lib = FALSE){

	if(lib) loadp(Seurat, ggplot2, dbplyr, RColorBrewer)
	print(paste('Start', as.character(date()), sep = '    '))
	source("/sibcb2/bioinformatics2/wangjiahao/code/workflow/scRNA_seq.R")
}

show_cols <- function(col, plot = FALSE){

	loadp(ggplot2)
	p <- ggplot(data.frame(col = factor(col, levels = rev(col))), aes(col))
	p <- p + geom_bar(aes(fill = rev(col)), width = 1)
	p <- p + scale_fill_manual(values = col)
	p <- p + scale_y_continuous(expand = c(0, 0))
	p <- p + theme(legend.position = "none") + labs(x = NULL, y = NULL)
	p <- p + theme(axis.text.x = element_blank(), panel.background = element_blank(), axis.ticks = element_blank())
	p <- p + theme(axis.text.y = element_text(face = "bold", size = 15))
	p <- p + coord_flip()
	if(plot){
		pdf("test.pdf", 3, 5)
			p
		dev.off()
	}
	return(p)
}

readCounts <- function(file){

	library(data.table)
	counts = fread(file)
	rownames(counts) = counts$Index
	counts$Index = NULL

	rows = rownames(counts)
	counts = data.frame(counts)
	rownames(counts) = rows
	colnames(counts) = gsub("\\.", "-", colnames(counts))
	return(counts)
}

readMeta <- function(file){

	meta <- read.table(file, sep = "\t", header = TRUE, row.names = 1, check.name = TRUE)
	return(meta)
}

creatSeuratObj <- function(countFile, metaFile){

	counts = readCounts(countFile)
	meta = readMeta(metaFile)
	obnj = CreateSeuratObject(counts = counts, meta.data = meta)
}


